﻿/*
 * Для работы с формой настройки цветов и выбора цветовых пространств
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiplomNN
{
    public partial class ColorsSettingsForm : Form
    {
        public ColorsSettingsForm()
        {
            InitializeComponent();
            SelfRef = this;
        }
        public static ColorsSettingsForm SelfRef
        {
            get;
            set;
        }
        public void UpdateColorSettFrFormPB()
        {
            ColorSettFrRGBPB.Image = Helper.ImageFilteredRGBPB;
            ColorSettFrHSVPB.Image = Helper.ImageFilteredHSVPB;
            ColorSettFrYCbCrPB.Image = Helper.ImageFilteredYCbCrPB;
        }

        private void ColorsSettingsForm_Load(object sender, EventArgs e)
        {
            Helper.IsActiveColorsSettingsForm = true;
            switch (Helper.MethodNumberColorsSettingsForm)
            {
                case 1:
                    {
                        radioButton1.Checked = true;
                        break;
                    }
                case 2:
                    {
                        radioButton2.Checked = true;
                        break;
                    }
                case 3:
                    {
                        radioButton3.Checked = true;
                        break;
                    }

            }
            # region Загрузка настроек в поля формы
            TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
            TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
            TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
            TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
            TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();

            TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
            TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
            TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
            TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
            TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
            TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();

            TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
            TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
            TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
            TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
            TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
            TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
            # endregion
        }

        private void ColorsSettingsForm_FormClosing(object sender, EventArgs e)
        {
            Helper.IsActiveColorsSettingsForm = false;
        }

        private void ColorSettFrSaveB_Click(object sender, EventArgs e)
        {
            # region Сохранение настроек в память программы
            Settings.Default.Rmax = Helper.ColorsSettFrRmax;
            Settings.Default.Rmin = Helper.ColorsSettFrRmin;
            Settings.Default.Gmax = Helper.ColorsSettFrGmax;
            Settings.Default.Gmin = Helper.ColorsSettFrGmin;
            Settings.Default.B = Helper.ColorsSettFrB;
            Settings.Default.RG = Helper.ColorsSettFrRG;
            
            Settings.Default.Hmax = Helper.ColorsSettFrHmax;
            Settings.Default.Hmin = Helper.ColorsSettFrHmin;
            Settings.Default.Smax = Helper.ColorsSettFrSmax;
            Settings.Default.Smin = Helper.ColorsSettFrSmin;
            Settings.Default.Vmax = Helper.ColorsSettFrVmax;
            Settings.Default.Vmin = Helper.ColorsSettFrVmin;

            Settings.Default.Ymax = Helper.ColorsSettFrYmax;
            Settings.Default.Ymin = Helper.ColorsSettFrYmin;
            Settings.Default.Cbmax = Helper.ColorsSettFrCbmax;
            Settings.Default.Cbmin = Helper.ColorsSettFrCbmin;
            Settings.Default.Crmax = Helper.ColorsSettFrCrmax;
            Settings.Default.Crmin = Helper.ColorsSettFrCrmin;
            # endregion
            Settings.Default.Save();
        }

        # region Работа с полем RedMax
        private void BRedMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrRmax < 254)
            {
                Helper.ColorsSettFrRmax += 1;
            }
            else
            {
                Helper.ColorsSettFrRmax = 255;
            }
            TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
        }

        private void BRedMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrRmax > Helper.ColorsSettFrRmin + 1)
            {
                Helper.ColorsSettFrRmax -= 1;
            }
            else
            {
                Helper.ColorsSettFrRmax = Helper.ColorsSettFrRmin;
            }
            TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
        }

        private void TBRedMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBRedMax.Text.ToString()) < Helper.ColorsSettFrRmin)
                {
                    Helper.ColorsSettFrRmax = Helper.ColorsSettFrRmin;
                    TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrRmax = int.Parse(TBRedMax.Text.ToString());
                    TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
            }
        }
        # endregion
        #region Работа с полем RedMin
        private void BRedMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrRmin < Helper.ColorsSettFrRmax - 1)
            {
                Helper.ColorsSettFrRmin += 1;
            }
            else
            {
                Helper.ColorsSettFrRmin = Helper.ColorsSettFrRmax;
            }
            TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
        }

        private void BRedMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrRmin > 1)
            {
                Helper.ColorsSettFrRmin -= 1;
            }
            else
            {
                Helper.ColorsSettFrRmin = 0;
            }
            TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
        }

        private void TBRedMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBRedMin.Text.ToString()) > Helper.ColorsSettFrRmax)
                {
                    Helper.ColorsSettFrRmin = Helper.ColorsSettFrRmax;
                    TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrRmin = int.Parse(TBRedMin.Text.ToString());
                    TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
            }
        }
        # endregion
        # region Работа с полем GreenMax
        private void BGreenMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrGmax < 254)
            {
                Helper.ColorsSettFrGmax += 1;
            }
            else
            {
                Helper.ColorsSettFrGmax = 255;
            }
            TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
        }

        private void BGreenMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrGmax > Helper.ColorsSettFrGmin + 1)
            {
                Helper.ColorsSettFrGmax -= 1;
            }
            else
            {
                Helper.ColorsSettFrGmax = Helper.ColorsSettFrGmin;
            }
            TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
        }
        private void TBGreenMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBGreenMax.Text.ToString()) < Helper.ColorsSettFrGmin)
                {
                    Helper.ColorsSettFrGmax = Helper.ColorsSettFrGmin;
                    TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrGmax = int.Parse(TBGreenMax.Text.ToString());
                    TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
            }
        }
        # endregion
        # region Работа с полем GreenMin
        private void BGreenMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrGmin < Helper.ColorsSettFrGmax - 1)
            {
                Helper.ColorsSettFrGmin += 1;
            }
            else
            {
                Helper.ColorsSettFrGmin = Helper.ColorsSettFrGmax;
            }
            TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
        }

        private void BGreenMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrGmin > 1)
            {
                Helper.ColorsSettFrGmin -= 1;
            }
            else
            {
                Helper.ColorsSettFrGmin = 0;
            }
            TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
        }

        private void TBGreenMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBGreenMin.Text.ToString()) > Helper.ColorsSettFrGmax)
                {
                    Helper.ColorsSettFrGmin = Helper.ColorsSettFrGmax;
                    TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrGmin = int.Parse(TBGreenMin.Text.ToString());
                    TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
            }
        }
        # endregion
        # region Работа с полем RedGreen
        private void BRedGreenMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrRG < 254)
            {
                Helper.ColorsSettFrRG += 1;
            }
            else
            {
                Helper.ColorsSettFrRG = 255;
            }
            TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();
        }

        private void BRedGreenMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrRG > -254)
            {
                Helper.ColorsSettFrRG -= 1;
            }
            else
            {
                Helper.ColorsSettFrRG = -255;
            }
            TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();
        }
        private void TBRedGreenMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBRedGreenMin.Text.ToString()) < -255)
                {
                    Helper.ColorsSettFrRG = -255;
                    TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();
                }
                else if (int.Parse(TBRedGreenMin.Text.ToString()) > 255)
                {
                    Helper.ColorsSettFrRG = 255;
                    TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();
                }
                else
                {
                    Helper.ColorsSettFrRG = int.Parse(TBRedGreenMin.Text.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();
            }
        }
        # endregion

        # region Работа с полем HueMax
        private void BHueMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrHmax < 359)
            {
                Helper.ColorsSettFrHmax += 1;
            }
            else
            {
                Helper.ColorsSettFrHmax = 360;
            }
            TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
        }

        private void BHueMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrHmax > Helper.ColorsSettFrHmin + 1)
            {
                Helper.ColorsSettFrHmax -= 1;
            }
            else
            {
                Helper.ColorsSettFrHmax = Helper.ColorsSettFrHmin;
            }
            TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
        }

        private void TBHueMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBHueMax.Text.ToString()) < Helper.ColorsSettFrHmin)
                {
                    Helper.ColorsSettFrHmax = Helper.ColorsSettFrHmin;
                    TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrHmax = int.Parse(TBHueMax.Text.ToString());
                    TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
            }
        }
        # endregion
        # region Работа с полем HueMin
        private void BHueMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrHmin < Helper.ColorsSettFrHmax - 1)
            {
                Helper.ColorsSettFrHmin += 1;
            }
            else
            {
                Helper.ColorsSettFrHmin = Helper.ColorsSettFrHmax;
            }
            TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
        }

        private void BHueMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrHmin > 1)
            {
                Helper.ColorsSettFrHmin -= 1;
            }
            else
            {
                Helper.ColorsSettFrHmin = 0;
            }
            TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
        }

        private void TBHueMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (int.Parse(TBHueMin.Text.ToString()) > Helper.ColorsSettFrHmax)
                {
                    Helper.ColorsSettFrHmin = Helper.ColorsSettFrHmax;
                    TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrHmin = int.Parse(TBHueMin.Text.ToString());
                    TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
            }
        }
        # endregion
        # region Работа с полем SaturationMax
        private void BSaturationMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrSmax < 0.99)
            {
                Helper.ColorsSettFrSmax += 0.01;
            }
            else
            {
                Helper.ColorsSettFrSmax = 1;
            }
            TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
        }

        private void BSaturationMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrSmax > Helper.ColorsSettFrSmin + 0.01)
            {
                Helper.ColorsSettFrSmax -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrSmax = Helper.ColorsSettFrSmin;
            }
            TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
        }

        private void TBSaturationMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBSaturationMax.Text.ToString()) < Helper.ColorsSettFrSmin)
                {
                    Helper.ColorsSettFrSmax = Helper.ColorsSettFrSmin;
                    TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrSmax = double.Parse(TBSaturationMax.Text.ToString());
                    TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
            }
        }
        # endregion
        # region Работа с полем SaturationMin
        private void BSaturationMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrSmin < Helper.ColorsSettFrSmax - 0.01)
            {
                Helper.ColorsSettFrSmin += 0.01;
            }
            else
            {
                Helper.ColorsSettFrSmin = Helper.ColorsSettFrSmax;
            }
            TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
        }

        private void BSaturationMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrSmin > 0.01)
            {
                Helper.ColorsSettFrSmin -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrSmin = 0;
            }
            TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
        }

        private void TBSaturationMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBSaturationMin.Text.ToString()) > Helper.ColorsSettFrSmax)
                {
                    Helper.ColorsSettFrSmin = Helper.ColorsSettFrSmax;
                    TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrSmin = double.Parse(TBSaturationMin.Text.ToString());
                    TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
            }
        }
        # endregion
        # region Работа с полем ValueMax
        private void BValueMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrVmax < 0.99)
            {
                Helper.ColorsSettFrVmax += 0.01;
            }
            else
            {
                Helper.ColorsSettFrVmax = 1;
            }
            TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
        }

        private void BValueMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrVmax > Helper.ColorsSettFrVmin + 0.01)
            {
                Helper.ColorsSettFrVmax -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrVmax = Helper.ColorsSettFrVmin;
            }
            TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
        }

        private void TBValueMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBValueMax.Text.ToString()) < Helper.ColorsSettFrVmin)
                {
                    Helper.ColorsSettFrVmax = Helper.ColorsSettFrVmin;
                    TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrVmax = double.Parse(TBValueMax.Text.ToString());
                    TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
            }
        }
        # endregion
        # region Работа с полем ValueMin
        private void BValueMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrVmin < Helper.ColorsSettFrVmax - 0.01)
            {
                Helper.ColorsSettFrVmin += 0.01;
            }
            else
            {
                Helper.ColorsSettFrVmin = Helper.ColorsSettFrVmax;
            }
            TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();
        }

        private void BValueMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrVmin > 0.01)
            {
                Helper.ColorsSettFrVmin -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrVmin = 0;
            }
            TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();
        }

        private void TBValueMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBValueMin.Text.ToString()) > Helper.ColorsSettFrVmax)
                {
                    Helper.ColorsSettFrVmin = Helper.ColorsSettFrVmax;
                    TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrVmin = double.Parse(TBValueMin.Text.ToString());
                    TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();
            }
        }
        # endregion

        # region Работа с полем YMax
        private void BYMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrYmax < 0.99)
            {
                Helper.ColorsSettFrYmax += 0.01;
            }
            else
            {
                Helper.ColorsSettFrYmax = 1;
            }
            TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
        }

        private void BYMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrYmax > Helper.ColorsSettFrYmin + 0.01)
            {
                Helper.ColorsSettFrYmax -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrYmax = Helper.ColorsSettFrYmin;
            }
            TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
        }

        private void TBYMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBYMax.Text.ToString()) < Helper.ColorsSettFrYmin)
                {
                    Helper.ColorsSettFrYmax = Helper.ColorsSettFrYmin;
                    TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrYmax = double.Parse(TBYMax.Text.ToString());
                    TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
            }
        }
        # endregion
        # region Работа с полем YMin
        private void BYMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrYmin < Helper.ColorsSettFrYmax - 0.01)
            {
                Helper.ColorsSettFrYmin += 0.01;
            }
            else
            {
                Helper.ColorsSettFrYmin = Helper.ColorsSettFrYmax;
            }
            TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
        }

        private void BYMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrYmin > 0.01)
            {
                Helper.ColorsSettFrYmin -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrYmin = 0;
            }
            TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
        }

        private void TBYMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBYMin.Text.ToString()) > Helper.ColorsSettFrYmax)
                {
                    Helper.ColorsSettFrYmin = Helper.ColorsSettFrYmax;
                    TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrYmin = double.Parse(TBYMin.Text.ToString());
                    TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
            }
        }
# endregion
        # region Работа с полем CbMax
        private void BCbMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrCbmax < 0.99)
            {
                Helper.ColorsSettFrCbmax += 0.01;
            }
            else
            {
                Helper.ColorsSettFrCbmax = 1;
            }
            TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
        }

        private void BCbMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrCbmax > Helper.ColorsSettFrCbmin + 0.01)
            {
                Helper.ColorsSettFrCbmax -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrCbmax = Helper.ColorsSettFrCbmin;
            }
            TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
        }

        private void TBCbMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBCbMax.Text.ToString()) < Helper.ColorsSettFrCbmin)
                {
                    Helper.ColorsSettFrCbmax = Helper.ColorsSettFrCbmin;
                    TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrCbmax = double.Parse(TBCbMax.Text.ToString());
                    TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
            }
        }
# endregion
        # region Работа с полем CbMin
        private void BCbMinUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrCbmin < Helper.ColorsSettFrCbmax - 0.01)
            {
                Helper.ColorsSettFrCbmin += 0.01;
            }
            else
            {
                Helper.ColorsSettFrCbmin = Helper.ColorsSettFrCbmax;
            }
            TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
        }

        private void BCbMinDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrCbmin > -0.99)
            {
                Helper.ColorsSettFrCbmin -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrCbmin = -1;
            }
            TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
        }

        private void TBCbMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBCbMin.Text.ToString()) > Helper.ColorsSettFrCbmax)
                {
                    Helper.ColorsSettFrCbmin = Helper.ColorsSettFrCbmax;
                    TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrCbmin = double.Parse(TBCbMin.Text.ToString());
                    TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
            }
        }
# endregion
        # region Работа с полем CrMax
        private void BCrMaxUp_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrCrmax < 0.99)
            {
                Helper.ColorsSettFrCrmax += 0.01;
            }
            else
            {
                Helper.ColorsSettFrCrmax = 1;
            }
            TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
        }

        private void BCrMaxDn_Click(object sender, EventArgs e)
        {
            if (Helper.ColorsSettFrCrmax > Helper.ColorsSettFrCrmin + 0.01)
            {
                Helper.ColorsSettFrCrmax -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrCrmax = Helper.ColorsSettFrCrmin;
            }
            TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
        }

        private void TBCrMax_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBCrMax.Text.ToString()) < Helper.ColorsSettFrCrmin)
                {
                    Helper.ColorsSettFrCrmax = Helper.ColorsSettFrCrmin;
                    TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
                }
                else
                {
                    Helper.ColorsSettFrCrmax = double.Parse(TBCrMax.Text.ToString());
                    TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
            }
        }
# endregion
        # region Работа с полем CrMin
        private void BCrMinUp_Click(object sender, EventArgs e)
        {
             if (Helper.ColorsSettFrCrmin < Helper.ColorsSettFrCrmax - 0.01)
            {
                Helper.ColorsSettFrCrmin += 0.01;
            }
            else
            {
                Helper.ColorsSettFrCrmin = Helper.ColorsSettFrCrmax;
            }
            TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
        }

        private void BCrMinDn_Click(object sender, EventArgs e)
        {
             if (Helper.ColorsSettFrCrmin > -0.99)
            {
                Helper.ColorsSettFrCrmin -= 0.01;
            }
            else
            {
                Helper.ColorsSettFrCrmin = -1;
            }
            TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
        }

        private void TBCrMin_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (double.Parse(TBCrMin.Text.ToString()) > Helper.ColorsSettFrCrmax)
                {
                    Helper.ColorsSettFrCrmin = Helper.ColorsSettFrCrmax;
                    TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
                }
                else
                {
                    Helper.ColorsSettFrCrmin = double.Parse(TBCrMin.Text.ToString());
                    TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
            }
        }
# endregion 

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            Helper.MethodNumberColorsSettingsForm = 1;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            Helper.MethodNumberColorsSettingsForm = 2;
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            Helper.MethodNumberColorsSettingsForm = 3;
        }

        private void BDefault_Click(object sender, EventArgs e)
        {
            Helper.ColorsSettFrRmax = 250;
            TBRedMax.Text = Helper.ColorsSettFrRmax.ToString();
            Helper.ColorsSettFrRmin = 90;
            TBRedMin.Text = Helper.ColorsSettFrRmin.ToString();
            Helper.ColorsSettFrGmax = 255;
            TBGreenMax.Text = Helper.ColorsSettFrGmax.ToString();
            Helper.ColorsSettFrGmin = 49;
            TBGreenMin.Text = Helper.ColorsSettFrGmin.ToString();
            Helper.ColorsSettFrRG = 0;
            TBRedGreenMin.Text = Helper.ColorsSettFrRG.ToString();

            Helper.ColorsSettFrHmax = 60;
            TBHueMax.Text = Helper.ColorsSettFrHmax.ToString();
            Helper.ColorsSettFrHmin = 0;
            TBHueMin.Text = Helper.ColorsSettFrHmin.ToString();
            Helper.ColorsSettFrSmax = 1;
            TBSaturationMax.Text = Helper.ColorsSettFrSmax.ToString();
            Helper.ColorsSettFrSmin = 0;
            TBSaturationMin.Text = Helper.ColorsSettFrSmin.ToString();
            Helper.ColorsSettFrVmax = 1;
            TBValueMax.Text = Helper.ColorsSettFrVmax.ToString();
            Helper.ColorsSettFrVmin = 0;
            TBValueMin.Text = Helper.ColorsSettFrVmin.ToString();

            Helper.ColorsSettFrYmax = 1;
            TBYMax.Text = Helper.ColorsSettFrYmax.ToString();
            Helper.ColorsSettFrYmin = 0.04;
            TBYMin.Text = Helper.ColorsSettFrYmin.ToString();
            Helper.ColorsSettFrCbmax = 0.04;
            TBCbMax.Text = Helper.ColorsSettFrCbmax.ToString();
            Helper.ColorsSettFrCbmin = -0.075;
            TBCbMin.Text = Helper.ColorsSettFrCbmin.ToString();
            Helper.ColorsSettFrCrmax = 0.08;
            TBCrMax.Text = Helper.ColorsSettFrCrmax.ToString();
            Helper.ColorsSettFrCrmin = 0.0055;
            TBCrMin.Text = Helper.ColorsSettFrCrmin.ToString();
        }
    }
}
